from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field


class StateBase(BaseModel):
    """状态基础模式"""
    name: str = Field(..., min_length=1, max_length=100, description="状态名称")
    code: str = Field(..., min_length=1, max_length=50, description="状态代码")
    description: Optional[str] = Field(None, description="状态描述")
    color: str = Field("#1890ff", description="状态颜色")
    icon: Optional[str] = Field(None, max_length=50, description="状态图标")
    module_type: str = Field(..., description="模块类型")
    is_enabled: bool = Field(True, description="是否启用")
    is_visible: bool = Field(True, description="是否可见")
    is_default: bool = Field(False, description="是否为默认状态")
    sort_order: int = Field(0, description="排序顺序")


class StateCreate(StateBase):
    """创建状态模式"""
    pass


class StateUpdate(BaseModel):
    """更新状态模式"""
    name: Optional[str] = Field(None, min_length=1, max_length=100, description="状态名称")
    description: Optional[str] = Field(None, description="状态描述")
    color: Optional[str] = Field(None, description="状态颜色")
    icon: Optional[str] = Field(None, max_length=50, description="状态图标")
    is_enabled: Optional[bool] = Field(None, description="是否启用")
    is_visible: Optional[bool] = Field(None, description="是否可见")
    is_default: Optional[bool] = Field(None, description="是否为默认状态")
    sort_order: Optional[int] = Field(None, description="排序顺序")


class StateResponse(StateBase):
    """状态响应模式"""
    id: str
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None


class ModuleStateResponse(BaseModel):
    """模块状态响应模式"""
    module_type: str = Field(..., description="模块类型")
    states: List[StateResponse] = Field(default_factory=list, description="状态列表")